//
//  TSMainHeaderView.swift
//  TSProfitProject
//
//  Created by TmmmS on 2019/10/29.
//  Copyright © 2019 TMS. All rights reserved.
//

import UIKit
import HandyJSON
import SDCycleScrollView

struct TSBannerModel : HandyJSON {
    var id : Int = 0
    var img : String? = nil
}

class TSMainHeaderView: UIView {

    let headerImg = UIImageView(image: UIImage(named: "main_header"))
    var bannerView : SDCycleScrollView!
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        configView()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func updateHeaderViewH(offsetY:CGFloat) {
        headerImg.snp.updateConstraints { (make) in
            make.height.equalTo(STATUSBAR_HEIGHT+150+offsetY)
        }
    }
    
    func setupHeaderView(array:Array<TSBannerModel>) {
        
        guard array.count != 0 else {
            return
        }
        
        var urlArray : Array<String> = []
        for model in array {
            urlArray.append(model.img!)
        }
        
        bannerView.imageURLStringsGroup = urlArray
    }
    
    func configView() {
        
        self.backgroundColor = WHITE_COLOR
        
        self.addSubview(headerImg)
        headerImg.snp.makeConstraints { (make) in
            make.left.top.right.equalToSuperview()
            make.height.equalTo(STATUSBAR_HEIGHT+150)
        }
        
        let imgScale = CGFloat(351.0 / 140.0)
        let bannerH = (SCREEN_WIDTH - 2*12) / imgScale
        bannerView = SDCycleScrollView.init()
        bannerView.layer.cornerRadius = 5
        bannerView.layer.masksToBounds = true
        bannerView.backgroundColor = WHITE_COLOR
        self.addSubview(bannerView)
        bannerView.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.bottom.equalToSuperview().inset(10)
            make.size.equalTo(CGSize(width: SCREEN_WIDTH - 2*12, height: bannerH))
        }
        
//        let logo = UIImageView.init(image: UIImage(named: "general_logo1"))
//        self.addSubview(logo)
//        logo.snp.makeConstraints { (make) in
//            make.centerX.equalToSuperview()
//            make.bottom.equalTo(bannerView.snp.top).offset(-5)
//            make.size.equalTo(CGSize(width: 80, height: 26))
//        }
        
    }

}
